package org.classdef.analyzer.info.constant;

/**
 * 
 Kind Description Interpretation 1 REF_getField getfield C.f:T 2 REF_getStatic
 * getstatic C.f:T 3 REF_putField putfield C.f:T 4 REF_putStatic putstatic C.f:T
 * 5 REF_invokeVirtual invokevirtual C.m:(A*)T 6 REF_invokeStatic invokestatic
 * C.m:(A*)T 7 REF_invokeSpecial invokespecial C.m:(A*)T 8 REF_newInvokeSpecial
 * new C; dup; invokespecial C.<init>:(A*)void 9 REF_invokeInterface
 * invokeinterface C.m:(A*)T
 * 
 */
public class MethodHandleInfo extends ConstantInfo {

	private byte referenceKind;
	private short referenceIndex;

	public MethodHandleInfo(short tag, byte referenceKind, short referenceIndex) {
		super(tag);
		this.referenceKind = referenceKind;
		this.referenceIndex = referenceIndex;
	}

	@Override
	public Object getValue() {
		StringBuilder sb = new StringBuilder();
		sb.append("{");
		sb.append("\"reference\":\"")
				.append(getPool().get(referenceIndex).getValue()).append("\"");
		sb.append("}");
		return sb.toString();
	}

	/*
	 * （非 Javadoc）
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("{");
		sb.append("\"tag\":").append(tag);
		sb.append(",\"referenceKind\":").append(referenceKind);
		sb.append(",\"referenceIndex\":").append(referenceIndex);
		sb.append("}");
		return sb.toString();
	}
}